from django import forms
from django.contrib import admin

from svn import models

'''
    Admin interface for repository class. 
    Users are allowed to add/edit/delete repositories via this interface.
'''
class RepositoryForm(forms.ModelForm):
    '''
        Designate the look of repository form. 
    '''
    class Meta:
        #Correct spelling of the plural form of "repository"
        model = models.Repository
    
    #Hide the password
    password = forms.CharField(
        max_length=512, required=False, widget=forms.PasswordInput)


class RepositoryAdmin(admin.ModelAdmin):
    '''
        Rearrange fields and put fields together.
    '''
    form = RepositoryForm

    fieldsets = (
        (None, {'fields': ('label', 'root', 'uri', 'is_private', 'force_accept_certificate')}),
        (u'Credentials', {'fields': ('username', 'password')}),
    )


admin.site.register(models.Repository, RepositoryAdmin)
